-----------------------------------------------------------------------------
-- 羁绊详情界面
--
---------------
-- Author: wd
-----------------------------------------------------------------------------
require 'Common/define'
require 'Logic/Config'
require 'Common/functions'

UIFetterDetial = {}
HelperFunc.SetUIEnv(UIFetterDetial)
local this = UIFetterDetial

this.hasInit = false
this.fetterDetialCfg = nil --羁绊配置表
this.fetterDetialList = {}--二维列表 key：人物id value：可解锁的羁绊列表
this.fetterAllCfgList = {}--列表  所有可解锁的羁绊列表
this.fetterUnLockList = {}--列表 当前所拥有英雄的下一级解锁羁绊
this.fetterShowList = {}--列表 展示的所有羁绊 fetterAllCfgList列表加fetterUnLockList列表

this.drawWrapper = nil
this.role_liHui = nil

this.HERO_ID = nil
this.START_CONST = 10
this._interval = 200
this.heroPic = nil;

this.fetterInfluencePage = nil;--羁绊总加成
this.btnAward = nil;--羁绊奖励按钮
function UIFetterDetial.Init(heroID)
    --HERO_ID = tonumber(heroID)

    local name, packageName = getUIName(PanelResNames.UIFetterDetial)
    panelMgr:ShowUI(name, packageName, this.OnCreate, Config.useLocalUI)
end

function UIFetterDetial.OnCreate(obj)
    this.isClosePanel = false
    if not hasInit then
        hasInit = true
        this.heroPic = obj:GetChild("hero");
        this.fetterInfluencePage = obj:GetChild("UIFetterInfluence");
        this.btnAward = obj:GetChild("btnAward")
        this.btnbgClose = obj:GetChild("bgClose")
        this.bind = {
            btnBack = obj:GetChild("btnBack"),
            heroIcon = obj:GetChild("HeroIcon"),
            dynamicList = obj:GetChild("elementList"),
            heroName = obj:GetChild("heroname"),
            btnOneKeyActive = obj:GetChild("btnOneKeyActive"),
            
        }
        -- this.bind.btnOneKeyActive.visible = false;
        obj:GetChild("n29").visible = false;
        obj:GetChild("n30").visible = false;
        this.bind.dynamicList.itemRenderer = this.refresHeroPosData
        this.bind.dynamicList:SetVirtual();

        this.wrapParent=obj:GetChild("wrapParent")
        this.effAward=this.btnAward:GetChild("n11")
        if effAward then
            this.effAwardWrap =this.effAward.wrapTarget
            this.effAward.visible=false
        end
        this.slotPos=Vector3.zero
        this.slots={}
        this.tweens={}
        this.effects={}
        this.wraps={}
        this.addEvent();
    end
    --[[if drawWrapper == nil then
        drawWrapper = GoWrapper.New();
    end--]]


    --this.bind.heroName.text = string.format(getLanguage("Trammel_Title"), getLanguage(G.dataTable["t_hero"][tostring(HERO_ID)]["f_HeroName"]));
    this.isFirst = true
    --this.ShowDrawing()
    this.UpdateElement()
    this.LocalListenEvent()

end

function UIFetterDetial.addEvent()
    this.removeEvent()
    this.bind.btnBack.onClick:Add(this.onClickBack)
    this.bind.btnOneKeyActive.onClick:Add(this.onOneKeyActive)
    this.btnbgClose.onClick:Add(this.onClickBack)
end

function UIFetterDetial.removeEvent()
    this.bind.btnBack.onClick:Clear()
    this.btnbgClose.onClick:Clear()
    this.bind.btnOneKeyActive.onClick:Clear()
end

function UIFetterDetial.LocalListenEvent()
    ListenEvent(Config.EventType.Fresh_FetterDetial, this.resetData)
    ListenEvent(Config.EventType.Fresh_FetterAward, this.UpdateAwardValue)
    ListenEvent(Config.EventType.FetterParticle, this.PlayParticle)

end

function UIFetterDetial.LocalCloseEvent()
    CloseEvent(Config.EventType.Fresh_FetterDetial, this.resetData)
    CloseEvent(Config.EventType.Fresh_FetterAward, this.UpdateAwardValue)
    CloseEvent(Config.EventType.FetterParticle,this.PlayParticle)
end


function UIFetterDetial.OnEnable()

end

function UIFetterDetial.OnDisable()
    this.LocalCloseEvent();
    --this.removeEvent();
    if this.tweenTimer ~= nil then
        utimer.remove(this.tweenTimer)
        this.tweenTimer = nil
    end
    if this.effTimer ~= nil then
        utimer.remove(this.effTimer)
        this.effTimer = nil
    end
    destroy(role_liHui)
    role_liHui = nil
    destroyGoWraper(drawWrapper)
    drawWrapper = nil
    -- for k,v in pairs(this.slots)do
    --     if not HelperFunc.IsNull(v) then
    --         v:Dispose()
    --     end
    --     this.slots[k]=nil
    -- end

    for k,v in pairs(this.wraps)do
        destroyGoWraper(this.wraps[k])
        this.wraps[k]=nil
    end
    for k,v in pairs(this.tweens) do
        this.tweens[k]:Kill()
        this.tweens[k]=nil
    end
    for k,v in pairs(this.effects)do
        destroy(this.effects[k])
        this.effects[k]=nil
    end
end
function UIFetterDetial.OnDestroy()
    --this.OnDisable()
    if equipHandler.refreshHeroList then
        equipHandler.refreshHeroList = nil
        FireEvent(Config.EventType.ReFreshHeroPower) 
    end
end
function UIFetterDetial.resetData()
    this.UpdateElement()
end

--- 更新英雄信息
function UIFetterDetial.GetHeroInfo()
    if fetterDetialCfg == nil then
        fetterDetialCfg = G.dataTable["t_trammel"]
    end

    fetterAllCfgList = {};--当前所有可解锁的羁绊
    fetterUnLockList = {};--所有英雄下一解锁羁绊
    local heroStarInfo = {}--为了减少获取英雄信息次数添加的中间列表{key:[英雄id] value：英雄星数 为0则英雄不存在}
    for _, info in pairs(fetterDetialCfg) do
        local heroStarNum = 0;
        if heroStarInfo[info.f_HeroID] == nil then
            local isHero = logicMgr.HeroManager.getHeroDatabyModelId(info.f_HeroID, true);
            if isHero == nil or (isHero ~= nil and isHero.partnerId == 0) then
                --没有该英雄
                heroStarInfo[info.f_HeroID] = 0;
            else
                heroStarInfo[info.f_HeroID] = isHero.star;
            end
        end
        heroStarNum = heroStarInfo[info.f_HeroID];
        if heroStarNum ~= 0 then
            if not this.CheckFetterActive(info.f_HeroID, info.f_Id) and heroStarNum >= info.f_HeroStar and logicMgr.HeroManager.getHandbookByModelId(info.f_HeroID, true) then
                table.insert(fetterAllCfgList, info)
            end
        end
    end
    table.sort(fetterAllCfgList, function(a, b)
        return a["f_Id"] < b["f_Id"]
    end)
    --添加当前所拥有英雄下一羁绊
    for k, v in pairs(heroStarInfo) do
        if v ~= 0 then
            local infos = HeroManager.GetFetterInfoByModelId(k);
            for i = 1, #infos do
                if infos[i].f_HeroStar == v then
                    if infos[i + 1] ~= nil then
                        table.insert(fetterUnLockList, infos[i + 1])
                    else
                        if this.CheckFetterActive(infos[i].f_HeroID, infos[i].f_Id) or logicMgr.HeroManager.getHandbookByModelId(infos[i].f_HeroID, true) == nil then
                            table.insert(fetterUnLockList, infos[i])
                        end
                    end
                end
            end
        end
    end
    table.sort(fetterUnLockList, function(a, b)
        return a["f_HeroStar"] < b["f_HeroStar"]
    end)
    fetterShowList = {};

    for i = 1, #fetterAllCfgList do
        table.insert(fetterShowList, fetterAllCfgList[i]);
    end
    for i = 1, #fetterUnLockList do
        table.insert(fetterShowList, fetterUnLockList[i]);
    end
    --return logicMgr.HeroManager.getHeroDatabyModelId(HERO_ID,true)
end
--更新羁绊详情页面
function UIFetterDetial.UpdateElement()
    this.GetHeroInfo()
    this.initFetterInfluence()
    this.UpdateAwardValue()
    --heroPic.url = EnumConst.AtlasPath.SmallBodyAtlas..config.smallIcon
    local redDot = this.bind.btnOneKeyActive:GetChild("UIRedDots")
    if table.getn(fetterAllCfgList) > 0 then
        redDot.visible = true;
        redDot:GetController("c1").selectedIndex = 2;
    else
        redDot.visible = false;
    end
    this.itemDataList = {};
    this.itemIdList = {};
    this.bind.dynamicList.numItems =0
    this.bind.dynamicList.numItems = #fetterShowList
    if this.isFirst then
        this.isFirst = false
        HelperFunc.ListTranstionPlay(this.bind.dynamicList)
        --local index = this.GetFirstAwardIndex()
        --this.bind.dynamicList:ScrollToView(index, true)  --是否需要跳到一个可以领取的位置
    end
end

--更新羁绊总加成
function UIFetterDetial.initFetterInfluence()
    local data = HeroManager.GetCalculateAllAttr();
    local list = this.fetterInfluencePage:GetChild("attrGroup");
    list:RemoveChildrenToPool();
    for i = 1, 3 do
        local item = list:AddItemFromPool()
        item:GetChild("Attr").text = getLanguage("Attr_" .. data[i].attrId)
        item:GetChild("number").text = getNumString(data[i].attrNum);
    end
    --for i,v in pairs(data)do
    --    local item = list:AddItemFromPool()
    --    item:GetChild("Attr").text = getLanguage("Attr_" .. v.attrId)
    --    item:GetChild("number").text = getNumString(v.attrNum);
    --end
end

function UIFetterDetial.ShowDrawing()
    --local CurHeroConfig = logicMgr.HeroManager.GetHeroConfigbyModelId(HERO_ID);
    --local imageName = logicMgr.HeroManager.GetHeroDrawingPath(HERO_ID)

    --[[
    resMgr:LoadModelPrefab(imageName, function(go)
        if (role_liHui ~= nil) then
            destroyImmediate(role_liHui);
            role_liHui = nil
        end

        role_liHui = newObject(go);
        role_liHui.name = "role_liHui";
        Util.AddAction(role_liHui, "idle1", true, 0.5);

        role_liHui:AddComponent(TCanvas);

        drawWrapper:SetWrapTarget(role_liHui, true)
        this.bind.heroIcon:SetNativeObject(drawWrapper);
        Util.Lua_SetLocalPositionXYZ(role_liHui.transform, 0, 0, 0);
        Util.Lua_SetLocalScaleXYZ(role_liHui.transform, 0.8, 0.8, 1)
    end)
    ]]
end

--- 刷新单个元素信息
function UIFetterDetial.refresHeroPosData(index, obj)
    index = index + 1
    local fetterData = fetterShowList[index]
    local myHeroInfo = logicMgr.HeroManager.getHeroDatabyModelId(fetterData.f_HeroID, true)
    local startNum = fetterData["f_HeroStar"] / START_CONST
    local shipe = obj:GetChild("effect_jbjh").wrapTarget;
    local showShipeController = obj:GetController("isShowShipe");

    ---- 事件侦听
    obj.onClick:Clear()
    -- 按钮状态
    local crtState = obj:GetController("c1")
    crtState.selectedIndex = 1
    if myHeroInfo then
        local myHeroStarNum = myHeroInfo["star"] / START_CONST
        if myHeroStarNum >= startNum and UIFetterDetial.CheckFetterActive(myHeroInfo.partnerModelId, fetterData["f_Id"]) then
            crtState.selectedIndex = 0;
        elseif myHeroStarNum >= startNum then
            --table.insert(this.itemDataList, { shipe = shipe, controller = showShipeController, index = index, id = fetterData["f_Id"] });
            --table.insert(this.itemIdList, fetterData["f_Id"]);
            local param = ActivateBondInfo.New()
            param.partnerId = myHeroInfo["partnerId"];
            param.bondId = {}
            table.insert(param.bondId, fetterData["f_Id"])
            obj.onClick:Add(function()
                this.onClickActive({ param });
                AudioManager.Play(AudioManager.Play_Fetter_active)
                local x = obj.x + obj.width / 2
                local y = obj.y + obj.height - this.bind.dynamicList.scrollPane.posY;
                this.slotPos=Vector3(x,y,0)
            end)
        else
            crtState.selectedIndex = 2;
        end
    end

    --未激活 无法领取
    if logicMgr.HeroManager.getHandbookByModelId(tostring(myHeroInfo.partnerModelId), true) == nil then
        crtState.selectedIndex = 2
    end

    -- 星级
    local txtStartNum = obj:GetChild("limit")
    txtStartNum.text = startNum

    -- 属性显示
    local attrList = decodeJsonStrToTabel(fetterData["f_AttributeBonus"])
    local count = table.nums(attrList)
    local function UpdateAttr(_index, atrObj)
        local key = _index + 1
        local attrInfo = attrList[key]
        local attrId = attrInfo[1]
        local attrNum = attrInfo[2]

        local attrSingle = G.dataTable["t_attributelibrary"][tostring(attrId)]
        local attrNumStr = attrSingle.f_AttributeType == 1 and string.format("%d", attrNum) or string.format("%s%%", tostring(attrNum / 100))
        local txtAttrValue = atrObj:GetChild("number")
        local txtAttrName = atrObj:GetChild("attr")
        txtAttrValue.text = "+" .. attrNumStr--string.TextColor(attrNumStr,"#61B71B")
        txtAttrName.text = getLanguage("Attr_" .. attrId);
        local icon = atrObj:GetChild("Icon")
        icon.url = EnumConst.AtlasPath.ICONAtlas .. "attr" .. attrId
    end
    local attrList = obj:GetChild("attrList")
    attrList.itemRenderer = UpdateAttr
    attrList.numItems = count
    --HelperFunc.ListTranstionPlay(attrList)

    local quality = obj:GetChild("quality");
    local qualityFrame = quality:GetChild("frame")
    local qualityIcon = quality:GetChild("icon")
    local qualityNumIcon = quality:GetChild("numIcon")
    local staegeController = quality:GetController("jinjie")
    local maxController = quality:GetController("LR");
    local config = G.dataTable.t_iconframe[tostring(startNum)]
    local isFrame = config.f_Ornaments ~= ""
    qualityFrame.visible = isFrame
    local atlas = "ui://CharactorUI/"
    if isFrame then
        qualityFrame.url = atlas .. config.f_QualityOrnaments
    end
    if config.f_QualityText ~= "" then
        qualityIcon.url = atlas .. config.f_QualityText
        staegeController.selectedIndex = 1;
    else
        staegeController.selectedIndex = 0;
    end
    qualityNumIcon.url = atlas .. config.f_QualityIcon
    if config.f_Id > 10 then
        staegeController.selectedIndex = 0;
        maxController.selectedIndex = startNum - 10;
    else
        maxController.selectedIndex = 0;
    end
    -- 羁绊值
    local fetterValue = obj:GetChild("Total")
    fetterValue.text = fetterData["f_TrammelPoint"]

    --头像
    local itemValue = logicMgr.HeroManager.getHeroDatabyModelId(fetterData["f_HeroID"])
    itemValue.star = fetterData["f_HeroStar"]
    itemValue.level = 0;
    local go = obj:GetChild("hero");
    go.enabled = false;
    local charactor = CtrlManager.GetCtrl(PanelNames.HeadRectItem);
    if charactor ~= nil then
        --初始英雄信息
        charactor.initData(go, itemValue);
        --charactor.updateDecTitle(go, itemValue, type,nil,self.formationType);
    end
    if crtState.selectedIndex == 2 then
        go.grayed = true;
    else
        go.grayed = false;
    end
end

--- 检测传入的羁绊id是否已经激活
function UIFetterDetial.CheckFetterActive(id, cfgID)
    local heroInfo = logicMgr.HeroManager.getHeroDatabyModelId(id, true)
    if heroInfo and heroInfo["fetter"] and heroInfo["fetter"][cfgID] then
        return true
    end
    return false
end
--一键解锁羁绊
function UIFetterDetial.onOneKeyActive()
    if table.getn(fetterAllCfgList) > 0 then
        equipHandler.refreshHeroList = true
        if fetterDetialCfg == nil then
            fetterDetialCfg = G.dataTable["t_trammel"]
        end
        local fetterDetialList = {};
        local heroStarInfo = {}--为了减少获取英雄信息次数添加的中间列表{key:[英雄id] value：英雄星数 为0则英雄不存在}
        for _, info in pairs(fetterDetialCfg) do
            local heroStarNum = 0;
            if heroStarInfo[info.f_HeroID] == nil then
                local isHero = logicMgr.HeroManager.getHeroDatabyModelId(info.f_HeroID, true);
                if isHero == nil or (isHero ~= nil and isHero.partnerId == 0) then
                    --没有该英雄
                    heroStarInfo[info.f_HeroID] = 0;
                else
                    heroStarInfo[info.f_HeroID] = isHero.star;
                end
            end
            heroStarNum = heroStarInfo[info.f_HeroID];
            if heroStarNum ~= 0 then
                if (not this.CheckFetterActive(info.f_HeroID, info.f_Id)) and heroStarNum >= info.f_HeroStar then
                    if fetterDetialList[info.f_HeroID] == nil then
                        fetterDetialList[info.f_HeroID] = ActivateBondInfo.New();
                        fetterDetialList[info.f_HeroID].partnerId = logicMgr.HeroManager.getHeroDatabyModelId(info.f_HeroID).partnerId;
                        fetterDetialList[info.f_HeroID].bondId = {}
                    end
                    table.insert(fetterDetialList[info.f_HeroID].bondId, info.f_Id);
                    table.sort(fetterDetialList[info.f_HeroID].bondId, function(a, b)
                        return a < b
                    end)
                end
            end
        end
        if table.getn(fetterDetialList) > 0 then
            local param = {}
            for k, v in pairs(fetterDetialList) do
                table.insert(param, v)
            end
            if table.getn(param) > 0 then
                partnerHandler.sendActiveFetter(param);
            end
        end
        AudioManager.Play(2011)
    else
        --无可升级的
        AudioManager.Play(2010)
        UISysTips.AddMsg(getLanguage("ErrorCode_420"));
    end

end

--- 点击 激活 羁绊
---data{
---     {
---         partnerId:英雄id
---         bondId:{羁绊id}
---     },...
---}
function UIFetterDetial.onClickActive(data)

    partnerHandler.sendActiveFetter(data);
    --
    --local myHeroInfo = this.GetHeroInfo()
    ----未激活
    --if logicMgr.HeroManager.getHandbookByModelId(tostring(myHeroInfo.partnerModelId), true) == nil then
    --    return
    --end
    --if myHeroInfo then
    --    local _index = 1
    --    local _length = #this.itemDataList + 1
    --    local _item
    --    local _scrollViewIndex = 0
    --    --utimer.remove(this.timerId)
    --    --this.timerId = utimer.timeCall(function()
    --    if _item then
    --        _item.controller.selectedIndex = 0
    --        _item = nil
    --    end
    --    if _index >= _length or this.isClosePanel then
    --        utimer.remove(this.timerId)
    --        this.timerId = nil
    --    else
    --        if #this.itemDataList > 0 then
    --            _item = this.itemDataList[1]
    --            partnerHandler.sendActiveFetter(myHeroInfo["partnerId"], { _item.id });
    --            _item.controller.selectedIndex = 1;
    --            Util.PlayAction(_item.shipe, "idle", false);
    --            _scrollViewIndex = _item.index
    --            if _scrollViewIndex >= this.bind.dynamicList.numItems then
    --                _scrollViewIndex = _scrollViewIndex - 1
    --            end
    --            --this.bind.dynamicList:ScrollToView(_scrollViewIndex, true)
    --        end
    --        _index = _index + 1
    --    end
    --end, this._interval, _length)

    -- for k, v in pairs(this.itemDataList) do
    --     utimer.timeCall(function ()
    --         partnerHandler.sendActiveFetter(myHeroInfo["partnerId"], {v.id});
    --         v.controller.selectedIndex = 1;
    --         Util.PlayAction(v.shipe, "idle", false);
    --         this.bind.dynamicList:ScrollToView(v.index, true);
    --     end , k*this._interval, 1);
    --     utimer.timeCall(function ()
    --         v.controller.selectedIndex = 0;
    --     end , k*this._interval + 500, 1);
    -- end
    --end
end

--刷新羁绊值显示状态
function UIFetterDetial.UpdateAwardValue()
    local fetterAwardCfg = G.dataTable["t_trammelpointreward"]
    local progressValue = 100;--进度条进度
    local fetterAwardList = {}
    local curIndex = 0;--当前解锁的奖励索引
    local showIndex = 0;--展示的奖励索引

    local progressBar = btnAward:GetChild("bar")
    local awardIcon = btnAward:GetChild("icon"):GetChild("icon")
    local awardText = btnAward:GetChild("title")--text："xx/xx"
    local awardNum = btnAward:GetChild("num")
    local iconSuit = btnAward:GetChild("iconSuit")--角标
    local stateEffCtrl = btnAward:GetController("state")--可领奖特效
    for _, info in pairs(fetterAwardCfg) do
        table.insert(fetterAwardList, info)
    end
    table.sort(fetterAwardList, function(a, b)
        return a["f_Id"] < b["f_Id"]
    end)
    fetterAwardList = table.reverse(fetterAwardList)

    local awardValue = logicMgr.HeroManager.GetHeroFetterAwardValue();--获得羁绊奖励点数
    local hadAwardTable = logicMgr. HeroManager.GetHeroFetterHadAwardList();--当前已领取羁绊奖励列表
    for i = 1, #fetterAwardList do
        local data = fetterAwardList[i];
        if awardValue >= data.f_Point then
            --当前羁绊值大于data的可领取数值
            if curIndex == 0 then
                --i为当前解锁
                curIndex = i;
            end

            if hadAwardTable[data.f_Id] then
                --该奖励已经领取
            else
                --未领取 显示该奖励
                showIndex = i;
            end
        end
    end
    if showIndex == 0 then
        --显示下一级的奖励
        local nextReward = fetterAwardList[curIndex - 1];
        stateEffCtrl.selectedIndex = 0;
        if nextReward == nil then
            nextReward = fetterAwardList[#fetterAwardList];
            progressValue = (awardValue / nextReward.f_Point) * 100;
        else
            progressValue = (awardValue / nextReward.f_Point) * 100;
        end
        local rewardId = decodeJsonStrToTabel(nextReward.f_Reward)[1][1];
        local rewardNum = decodeJsonStrToTabel(nextReward.f_Reward)[1][2];
        local constData = ItemManager.getItemConstDatabyModelId(rewardId)
        if constData and constData.cornerMark ~= "" then
            iconSuit.visible = true;
            iconSuit.url = EnumConst.AtlasPath.ICONAtlas .. constData.cornerMark;
        else
            iconSuit.visible = false;
        end
        local imgUrl = ItemManager.GetItemIconPath(rewardId);
        awardText.text = string.format(getLanguage("TrammelTips1"), awardValue, nextReward.f_Point);
        progressBar.value = progressValue;
        awardIcon.url = imgUrl;
        awardNum.text = rewardNum;
        partnerHandler.canClickFetterAward=true
        btnAward.onClick:Clear()
        btnAward.onClick:Add(function()
            equipHandler.refreshHeroList = true
            showUI(PanelNames.UIFetterAward)

        end)

    else
        --显示可领取的奖励
        local showReward = fetterAwardList[showIndex];
        stateEffCtrl.selectedIndex = 1;
        local rewardId = decodeJsonStrToTabel(showReward.f_Reward)[1][1];
        local rewardNum = decodeJsonStrToTabel(showReward.f_Reward)[1][2];
            local constData = ItemManager.getItemConstDatabyModelId(rewardId)
        if constData and constData.cornerMark ~= "" then
            iconSuit.visible = true;
            iconSuit.url = EnumConst.AtlasPath.ICONAtlas .. constData.cornerMark;
        else
            iconSuit.visible = false;
        end
        local imgUrl = ItemManager.GetItemIconPath(rewardId);
        awardText.text = string.format(getLanguage("TrammelTips1"), awardValue, showReward.f_Point);
        progressBar.value = progressValue;
        awardIcon.url = imgUrl;
        awardNum.text = rewardNum;
        btnAward.onClick:Clear()
        btnAward.onClick:Add(function()
            if(partnerHandler.canClickFetterAward)then
                partnerHandler.canClickFetterAward=false
                equipHandler.refreshHeroList = true
                partnerHandler.sendFetterAward(showReward.f_Id)
            end
        end)
    end
end
function UIFetterDetial.PlayParticle()
    resMgr:LoadModelPrefab("UIEff/efc_jblq", function(go)
        local slot=GGraph.New()
        if this.wrapParent ~= nil then
            this.wrapParent:AddChild(slot)
        end
        slot.position=this.slotPos
        local wrap=GoWrapper.New()
        local effect=newObject(go)
        -- table.insert(this.slots,slot)
        -- table.insert(this.wraps,wrap)
        -- table.insert(this.effects,effect)
        slot.displayObject.visible=true
        effect.name = "efc_jblq"
        effect:AddComponent(TCanvas)
        wrap:SetWrapTarget(effect, false)
        slot:SetNativeObject(wrap)
        Util.Lua_SetLocalPositionXYZ(effect.transform, 0, 0, 0)
        --local x = btnAward.x + btnAward.width / 2
        --local y = btnAward.y + btnAward.height / 2
        local x = btnAward.x
        local y = btnAward.y
        local tween = slot:TweenMove(x, y, 1.5):SetDelay(0.2)
        tween:SetEase(EaseType.QuintOut)
        tween:OnComplete(function()
            --slot.displayObject.gameObject:SetActive(false)
            wrap:Dispose()
            destroy(effect)
        end)
    end)
end
function UIFetterDetial.onClickBack()
    --this.isClosePanel = true
    logicMgr.HeroManager.ClerPool()
    closeUI(PanelNames.UIFetterDetial)
end
--
--function UIFetterDetial.GetFirstAwardIndex()
--    local index = 0
--    local myHeroInfo = this.GetHeroInfo()
--    if myHeroInfo then
--        for k, fetterData in pairs(fetterDetialList) do
--            local hadActive = this.CheckFetterActive(fetterData["f_Id"])
--            if myHeroInfo["star"] >= fetterData["f_HeroStar"] then
--                if not hadActive then
--                    index = k
--                    break
--                end
--            else
--                index = k
--                break
--            end
--        end
--    end
--    index = index - 1 --FGUI下标从0开始
--    if index < 0 then
--        index = 0
--    end
--    return index
--end


return UIFetterDetial
